package com.story.pr;

import java.util.ArrayList;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

public class Story {

	public ArrayList<String> short_title;
	public ArrayList<String> cover;
	public ArrayList<String> title;
	public ArrayList<Integer> rate;
	public ArrayList<String> description;
	public int slbg = 0;

	public Story getStoryAll(String str) {

		final String SOAP_ACTION = "http://tempuri.org/SellectAll";
		final String METHOD_NAME = "SellectAll";
		final String NAMESPACE = "http://tempuri.org/";
		final String URL = "http://10.0.2.2:57232/Service1.asmx";

		SoapObject table = null;
		SoapObject client = null;
		SoapObject tableRow = null;
		SoapObject responseBody = null;
		SoapSerializationEnvelope sse = null;
		sse = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		sse.addMapping(NAMESPACE, "Story", this.getClass());
		sse.dotNet = true;
		AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(
				URL);
		Story story = new Story();

		try {
			client = new SoapObject(NAMESPACE, METHOD_NAME);
			client.addProperty("str", str);
			sse.setOutputSoapObject(client);
			sse.bodyOut = client;
			androidHttpTransport.call(SOAP_ACTION, sse);
			responseBody = (SoapObject) sse.getResponse();
			responseBody = (SoapObject) responseBody.getProperty(1);
			table = (SoapObject) responseBody.getProperty(0);
			
			story.slbg = table.getPropertyCount();
			story.short_title = new ArrayList<String>();
			story.cover = new ArrayList<String>();
			story.title = new ArrayList<String>();
			story.description = new ArrayList<String>();
			story.rate = new ArrayList<Integer>();

			for (int i = 0; i < story.slbg; i++) {
				tableRow = (SoapObject) table.getProperty(i);
				story.short_title.add(tableRow.getProperty("SHORT_TITLE")
						.toString());

				story.cover.add(tableRow.getProperty("COVER").toString());
				story.title.add(tableRow.getProperty("TITLE").toString());
				story.description.add(tableRow.getProperty("DESCRIPTION")
						.toString());
				story.rate.add(Integer.valueOf(tableRow.getProperty("RATE")
						.toString()));

			}
			return story;

		} catch (Exception e) {
			story.short_title.add(e.toString());
			story.cover.add(e.toString());
			story.title.add(e.toString());
			story.description.add(e.toString());
			story.rate.add(Integer.valueOf(e.toString()));
			story.slbg = 0;
			return story;
		}

	}
}
